package com.tiger.web.controller.project;

import com.tiger.common.annotation.Log;
import com.tiger.common.core.controller.BaseController;
import com.tiger.common.core.domain.AjaxResult;
import com.tiger.common.core.domain.model.LoginUser;
import com.tiger.common.core.page.TableDataInfo;
import com.tiger.common.enums.BusinessType;
import com.tiger.common.utils.ServletUtils;
import com.tiger.common.utils.spring.SpringUtils;
import com.tiger.framework.web.service.TokenService;
import com.tiger.project.domain.Asset;
import com.tiger.project.domain.BookValue;
import com.tiger.project.service.IAssetService;
import com.tiger.project.service.IBookValueService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 【账面价值】Controller
 *
 * @author standard
 * @date 2022-09-15
 */
@Api(tags = "账面价值")
@RestController
@RequestMapping("/system/value")
public class BookValueController extends BaseController {
    @Autowired
    private IBookValueService bookValueService;
    @Autowired
    private IAssetService assetService;

    /**
     * 查询【账面价值】列表
     */
    @ApiOperation(value = "查询【账面价值】列表")
    //@PreAuthorize("@ss.hasPermi('system:value:list')")
    @GetMapping("/list")
        public TableDataInfo list(BookValue bookValue) {
        LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
        bookValue.setCompanyId(loginUser.getUser().getDeptId());
        startPage();
        List<BookValue> list = bookValueService.selectBookValueList(bookValue);
        return getDataTable(list);
    }



    /**
     * 获取【账面价值】详细信息
     */
    @ApiOperation(value = "获取【账面价值】列详细信息")
    //@PreAuthorize("@ss.hasPermi('system:value:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(bookValueService.selectBookValueById(id));
    }

    /**
     * 新增【账面价值】
     */
    @ApiOperation(value = "新增【账面价值】")
    //@PreAuthorize("@ss.hasPermi('system:value:add')")
    @Log(title = "新增【账面价值】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody BookValue bookValue) {
        LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
        bookValue.setCompanyId(loginUser.getUser().getDeptId());
        return toAjax(bookValueService.insertBookValue(bookValue));
    }

    /**
     * 修改【账面价值】
     */
    @ApiOperation(value = "修改【账面价值】")
    //@PreAuthorize("@ss.hasPermi('system:value:edit')")
    @Log(title = "修改【账面价值】", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody BookValue bookValue) {
        return toAjax(bookValueService.updateBookValue(bookValue));
    }

    /**
     * 删除【账面价值】
     */
    @ApiOperation(value = "删除【账面价值】")
    //@PreAuthorize("@ss.hasPermi('system:value:remove')")
    @Log(title = " 删除【账面价值】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bookValueService.deleteBookValueByIds(ids));
    }


    /**
     * 关联资产
     */
    @ApiOperation(value = "关联资产")
    //@PreAuthorize("@ss.hasPermi('system:asset:list')")
    @GetMapping("/assetList")
    public TableDataInfo assetList(Asset asset) {
        LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
        asset.setCompanyId(loginUser.getUser().getDeptId());
        startPage();
        List<Asset> list = assetService.selectAssetBookList(asset);
        return getDataTable(list);
    }
}
